package controle;

import gui.Gui;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ClienteProtocoloListener extends Thread implements SocketControlConstants{
	private ServerSocket serverSocket;
	private Gui gui;
	
	public ClienteProtocoloListener(Gui gui)
	{
		this.gui = gui;
	}
	
	public void run()
	{
		try
		{
			this.serverSocket = new ServerSocket(SocketControlConstants.portaProtocoloServidorCliente);
			
			while(true)
			{
				System.out.println("Esperando uma resposta do servidor...");
				Socket conexao = this.serverSocket.accept();
				System.out.println("Recebida a resposta do servidor, tratando a resposta...");
				ClienteProtocoloHandler clienteProtocoloHandler = new ClienteProtocoloHandler(conexao, gui);
				clienteProtocoloHandler.start();
			}
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	}

}